package com.android.love.adapter;

import java.util.Collections;
import java.util.LinkedList;
import java.util.List;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Paint;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.ImageView.ScaleType;

import com.android.love.R;
import com.android.love.util.ActivityUtil;
import com.android.love.util.ImageUtils;
import com.android.love.util.LogUtil;
import com.android.love.vo.Goods;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.assist.ImageLoadingListener;
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
import com.nostra13.universalimageloader.core.assist.SimpleImageLoadingListener;
import com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer;

public class CommentAdapter extends BaseAdapter {
	private static final String TAG = "CommentAdapter";
	private ImageLoader loader;
	private List<Goods> goods = Collections.emptyList();;
	private Context context;
	private int arrange_type;

	public CommentAdapter(Context context, ImageLoader loader,
			List<Goods> goods, int arrange_type) {
		super();
		this.context = context;
		this.loader = loader;
		this.goods = goods;
		this.arrange_type = arrange_type;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return goods.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return goods.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView == null) {
			if (arrange_type == 0)
				convertView = View.inflate(context, R.layout.grid_item, null);
			else
				convertView = View.inflate(context, R.layout.detai_item, null);
			holder = new ViewHolder();
			holder.iv_comment_img = (ImageView) convertView
					.findViewById(R.id.iv_comment_img);
			holder.tv_comment_title = (TextView) convertView
					.findViewById(R.id.tv_comment_title);
			holder.tv_comment_price = (TextView) convertView
					.findViewById(R.id.tv_comment_price);
			holder.tv_comment_old_price = (TextView) convertView
					.findViewById(R.id.tv_comment_old_price);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		// Goods good = new Goods();
		Goods good = goods.get(position);
		holder.tv_comment_title.setText(good.getGoods_name());
		holder.tv_comment_price.setText("￥" + good.getPrice() + "");
		holder.tv_comment_price.getPaint().setFlags(
				Paint.FAKE_BOLD_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG);
		holder.tv_comment_old_price.setText("￥" + good.getOld_price() + "");
		holder.tv_comment_old_price.getPaint().setFlags(
				Paint.STRIKE_THRU_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG);
		// loader.displayImage(good.getGoods_image(), holder.iv_comment_img,
		// options, animateFirstListener);
		if (arrange_type == 0)
			loader.displayImageForSize(good.getGoods_image(),
					holder.iv_comment_img,
					ImageUtils.getOptions(R.drawable.zw1),
					new SimpleImageLoadingListener(), 0, 0, 0, 0, 0, 0, 2f,
					true);
		else
			loader.displayImageForSize(good.getGoods_image(),
					holder.iv_comment_img,
					ImageUtils.getOptions(R.drawable.zw2),
					new SimpleImageLoadingListener(), 10, 10, 10, 10, 0, 0, 4f,
					true);
		return convertView;
	}

	public static class ViewHolder {
		TextView tv_comment_title;
		ImageView iv_comment_img;
		TextView tv_comment_price;
		TextView tv_comment_old_price;
	}

}
